var TChannelAsThrift = require('tchannel/as/thrift');
var TChannel = require('tchannel');
var fs = require('fs');
var path = require('path');
var int64_util = require('./node_modules/thrift/lib/nodejs/lib/thrift/int64_util');
// var int64_util = thrift.TJSONProtocol.int64_util // require('./int64_util');
var server = TChannel({serviceName: 'server'});
var Int64 = require('node-int64');
var client = TChannel();
var echoChannel = client.makeSubChannel({
    serviceName: 'echo1',
    peers: ['127.0.0.1:4030']
});
var tchannelAsThrift = TChannelAsThrift({
    channel: echoChannel,
    entryPoint: path.join(__dirname, 'thrifts/echo.thrift')
});

var context = {};
tchannelAsThrift.register(server, 'Echo::echo', context, echo);
function echo(context, req, head, body, callback) {

                var o1 = new Int64(body.value);
                var orderid = int64_util.toDecimalString(o1);
    // console.log("server get",body.value.toString());
     console.log("server get",body.value,orderid);
    callback(null, {
        ok: true,
        head: head,
        body: {value:orderid}
    });
}

server.listen(4030, '127.0.0.1', onListening);
function onListening() {
    
        // server.close();
   
}